/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.cid.entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;

/**
 *
 * @author hansena
 */
@Entity
@NamedQuery(
    name="findAllCustomers",
    query="SELECT c FROM Customer c"
    )
public class Customer implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @NotNull
    String fname;
    @NotNull
    String lname;
    String email;
    @Column(name= "PASSWORD", nullable = false)
    String pass;
    @Embedded
    Address address = new Address();
    @OneToMany(mappedBy = "customer", cascade = {CascadeType.PERSIST, CascadeType.REMOVE},
    fetch = FetchType.LAZY)
    List<PurchaseOrder> pOrders;

    public Customer() {
    }

    public Customer(String fname, String lname, String email, Address address) {
        this.fname = fname;
        this.lname = lname;
        this.email = email;
        this.address = address;

    }

    public List<PurchaseOrder> getpList() {
        return pOrders;
    }

    public void setpList(List<PurchaseOrder> pOrders) {
        this.pOrders = pOrders;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    public String getLname() {
        return lname;
    }

    public void setLname(String lname) {
        this.lname = lname;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<PurchaseOrder> getpOrders() {
        return pOrders;
    }

    public void setpOrders(List<PurchaseOrder> pOrders) {
        this.pOrders = pOrders;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 50 + hash + (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.chl.sasanf.jpa.nbp.Customer[id=" + id + "]";
    }


}
